import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:high_help_apps/common/routes/app_pages.dart';
import 'package:high_help_apps/common/utils/toast.dart';

import 'sign_up_state.dart';

class SignUpLogic extends GetxController {
  final state = SignUpState();

  // /// 用户名处理器
  // TextEditingController usernameController = new TextEditingController();
  // /// 密码处理器
  // TextEditingController passwordController = new TextEditingController();
  // /// 确认密码处理器
  // TextEditingController rePasswordController = new TextEditingController();

  @override
  void onClose() {
    // TODO: implement onClose
    super.onClose();
    // usernameController.dispose();
    // passwordController.dispose();
    // rePasswordController.dispose();
  }

  /// 跳转到登录界面
  void redirectLoginPage() {
    Get.toNamed(AppRoutes.SIGN_IN);
  }

  /// 用户注册
  void registerUser(String username, String password, String rePassword) {
    if(username == '' || password == '' || rePassword == '') {
      toastInfo(msg: '注册信息不能为空');
      return;
    }
    if(username.length < 6 || password.length < 6 || rePassword.length < 6) {
      toastInfo(msg: '用户名和密码不能小于6位');
      return;
    }
    if(password != rePassword) {
      toastInfo(msg: '两次密码输入不一致');
      return;
    }
    Get.offAndToNamed(AppRoutes.SIGN_UP_STEP, arguments: {
      'username': username,
      'password': password
    });
  }
}
